package com.snail.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.snail.model.pojo.media.BizCollection;
import com.snail.model.pojo.media.BizCollectionWorks;
import com.snail.model.query.media.CollectionAddQuery;
import com.snail.model.query.media.CollectionListQuery;
import com.snail.model.vo.media.CollectionWorksDetailVo;
import com.snail.model.vo.user.LoginUser;
import com.snail.result.PageResult;
import com.snail.result.Result;
import com.snail.service.BizCollectionService;
import com.snail.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Monica
 * @description
 * @date 2025/8/19 11:12
 */

@RestController
@RequestMapping("/collection")
public class BizCollectionController {

   @Autowired
   private BizCollectionService bizCollectionService;

   @PostMapping("/addCollection")
    public Result<BizCollection> addCollection(@RequestBody CollectionAddQuery query) {
       LoginUser currentUser = SecurityUtils.getCurrentUser();
      query.setUserId(currentUser.getUserId());
      BizCollection bizCollection = bizCollectionService.addCollection(query);
      return Result.success(bizCollection);
   }
   @GetMapping("/getCollectionList")
   public PageResult<BizCollection> getCollectionList(CollectionListQuery query) {
      LoginUser currentUser = SecurityUtils.getCurrentUser();
      query.setUserId(currentUser.getUserId());
       Page<BizCollection> page = bizCollectionService.getCollectionList(query);
       return PageResult.success(page);
   }
    @GetMapping("/getCollectionsByUserId")
    public PageResult<BizCollection> getCollectionsByUserId(CollectionListQuery query) {
        Page<BizCollection> page = bizCollectionService.getCollectionList(query);
        return PageResult.success(page);
    }
   @PostMapping("/deleteCollection")
   public Result<BizCollection> deleteCollection(@RequestBody Integer id) {
      bizCollectionService.removeById(id);
      return Result.success();
   }

   @PostMapping("/updateCollection")
   public Result<BizCollection> updateCollection(@RequestBody BizCollection bizCollection) {
      bizCollectionService.updateById(bizCollection);
      return Result.success();
   }

   @GetMapping("/getCollectionWorksDetail")
   public Result<CollectionWorksDetailVo> getCollectionWorksDetail(Integer collectionId) {
       CollectionWorksDetailVo collectionWorksDetail = bizCollectionService.getCollectionWorksDetail(collectionId);
      return Result.success(collectionWorksDetail);
   }

    @GetMapping("/getCollectionByWorkId")
    public Result<List<CollectionWorksDetailVo>> getCollectionByWorkId(Integer collectionId) {
        List<CollectionWorksDetailVo> collectionWorksDetail = bizCollectionService.getCollectionByWorkId(collectionId);
        return Result.success(collectionWorksDetail);
    }
}
